package com.thomasgustavo.meugood;



public class Transacao {
	
	private String transacao;
	
	private boolean cartaoPremium;

	public Transacao(String transacao, boolean cartaoPremium) {
		this.transacao = transacao;
		this.cartaoPremium = cartaoPremium;
	}
	
	public String getData(){
		if( cartaoPremium ){
			return getDataPremium();
		} else {
			return getDataPlus();
		}
	}
	
	private String getDataPlus() {
		return StringUtils.getConteudo(transacao, "<td>", "</td>");
	}

	private String getDataPremium() {
		return StringUtils.getConteudo(transacao, "<td class=\"EInfo2\" align=\"center\">", "</td>");
	}

	public String getLocal(){
		if( cartaoPremium ){
			return getLocalPremium();
		} else {
			return getLocalPlus();
		}
	}
	
	private String getLocalPremium() {
		String aux = transacao;
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2\">") + 1);
		return StringUtils.getConteudo(aux, "<td class=\"EInfo2\">", "</td>");
	}

	private String getLocalPlus() {
		return StringUtils.getConteudo(transacao, "<td align=\"left\">", "</td>");
	}

	public String getValorDebito(){
		if( cartaoPremium ){
			return getValorDebitoPremium();
		} else {
			return getValorDebitoPlus();
		}
	}

	private String getValorDebitoPremium() {
		String aux = transacao;
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		return StringUtils.getConteudo(aux, "<td class=\"EInfo2\" align=\"right\">", "</td>");
	}

	private String getValorDebitoPlus() {
		return StringUtils.getConteudo(transacao, "<td align=\"right\">", "</td>");
	}
	
	public String getValorCredito(){
		if( cartaoPremium ){
			return getValorCreditoPremium();
		} else {
			return null;
		}
	}

	private String getValorCreditoPremium() {
		String aux = transacao;
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		aux = aux.substring(aux.indexOf("<td class=\"EInfo2") + 1);
		return StringUtils.getConteudo(aux, "<td class=\"EInfo2\" align=\"right\">", "</td>");
	}

	public static boolean isTransacaoPremium(String str) {
		return str.contains("****");
	}
}
